<?php


namespace app\api\controller;


use logicmodel\ConfigLogic;
use logicmodel\SendLogic;
use logicmodel\UserLogic;
use logicmodel\WxLogic;
use think\Controller;
use think\Request;
use validate\ForgetPhonePasswordValidate;
use validate\RegisterValidate;

class Login extends Controller
{
    private $userLogic;
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->userLogic = new UserLogic();
    }

    /**
     * 登录
     * @param $phone
     * @param $password
     * @return \think\response\Json
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function login($phone,$password){
        return json($this->userLogic->login($phone,$password));
    }

    /**
     * 手机号快捷登录
     * @param $phone
     * @param $code
     * @param string $uuid
     * @return \think\response\Json
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function phoneLogin($phone,$code,$uuid=''){
        return json($this->userLogic->phoneLogin($phone,$code,$uuid));
    }

    /**
     * 会员注册
     * @param $uuid
     * @param $phone
     * @param $password
     * @param $pay_password
     * @param $code
     * @return \think\response\Json
     * @throws \app\lib\exception\ParamException
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function register($uuid,$phone,$password,$pay_password,$code){
        (new RegisterValidate())->goCheck();
        return json($this->userLogic->register($uuid,$phone,$password,$pay_password,$code));
    }

    /**
     * 忘记密码
     * @param $phone
     * @param $code
     * @param $password
     * @return \think\response\Json
     * @throws \app\lib\exception\ParamException
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function forgetPassword($phone,$code,$password){
        (new ForgetPhonePasswordValidate())->goCheck();
        return json($this->userLogic->forgetPassword($phone,$code,$password));
    }

    /**
     * 发送验证码
     * * @param  $phone
     * @param int $type
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function sendCode($phone,$type=1){
        return json((new SendLogic())->sendPhone($phone,$type));
    }

    /**
     * NFT介绍
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function nft(){
        return json((new ConfigLogic())->nft());
    }

    /**
     * 公司介绍
     * @return \think\response\Json
     */
    public function company(){
        return json((new ConfigLogic())->company());
    }

    /**
     * 系统配置
     * @return \think\response\Json
     */
    public function helpContent(){
        return json((new ConfigLogic())->helpContent());
    }

    /**
     * 客服配置
     * @return \think\response\Json
     */
    public function serverConfig(){
        return json((new ConfigLogic())->serverConfig());
    }
    /**
     * 微信公众号授权
     * @param $code
     * @return \think\response\Json
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function auth($code){
        return json((new WxLogic())->auth($code));
    }
}